
const apis = require('../../../utils/api').apis;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navData: [],
    nav_active: 0,
    otherCertificate:[],
    myCertificate:[],
    searchWord:"",
    searchResultArr:[],
    show:false,
    searchTotal:0,
    searchResultNum:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.getMy()
    this.getIndustry()
  },
  FoucsValue(e){
    let val=e.detail.val;
    if(val==''){
      this.setData({
        show:false
      })
    }
  },
  confirmValue(e){
    let val=e.detail.val;
    this.setData({
      searchWord:val
    })
    if(val!==''){
      this.setData({
        show:true,
        searchResultNum:1
      })
      this.getSearch()

    }else{
      this.setData({
        show:false,
        searchResultNum:1
      })
    }
  },
  getMy() {
    wx.showLoading({
      title: '加载中',
    })
    apis.certificateQueryMyIndustryAll().then(res => {
      // console.log(res)
      this.setData({
        myCertificate:res.data
      })
      wx.hideLoading()
    })
  },
  getIndustry() {
    let arr = []
    apis.certificateQueryOtherIndustry({}).then(res => {
      // res.data.map(item => {
      //   if (item.certificateBOs) {
      //     arr.push(item)
      //   }
      // })
      this.setData({
        navData: res.data
      })
      this.getOther(this.data.navData[0].id)

    })
  },
  getOther(id){
    apis.certificateQueryCertificateByIndustry({
      industryId:id
    }).then(res=>{
      if(res.data.length>0){
        this.setData({
          otherCertificate:res.data[0].certificateBOs
        })
      }else{
        this.setData({
          otherCertificate:[]
        })
      }
    })
  },
  goDeatil(e){
    let id=e.currentTarget.dataset.id;
    wx.navigateTo({
      url: '../index_zhengshu_detail/index?id='+id,
    })
  },
  switchTap(e){
    let active=e.currentTarget.dataset.index;
    let id=e.currentTarget.dataset.id;
    this.setData({
      nav_active:active
    })
    this.getOther(id)
  },
  getSearch(){
    apis.certificateQueryCertificateByName({
      name:this.data.searchWord,
      pageNo:this.data.searchResultNum,
      pageSize:15
    }).then(res=>{
      console.log(res)
     if(this.data.searchResultNum==1){
      this.setData({
        searchResultArr:res.data.records,
        searchTotal:res.data.total
      })
     }else{
      this.setData({
        searchResultArr:this.data.searchResultArr.concat(res.data.records),
        searchTotal:res.data.total
      })
     }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    console.log(this.data.total)
    if(this.data.searchTotal>this.data.searchResultArr.length){
      this.setData({
        searchResultNum: ++this.data.searchResultNum
      })
      console.log(this.data.searchResultNum)
      this.getSearch()
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})